<?php
class ConfigModel {
	
	private $config_file_path;
	private $config_file_content;
	
	public function init(){
		$this->config_file_path = APPLICATION_PATH . '/configs/constant.ini';
		$this->config_file_content = file_get_contents($this->config_file_path);
		
		$config_file = file_get_contents(APPLICATION_PATH . '/configs/constant.ini');
    	$result = preg_replace("/CANCEL_FEE = [0-9]*/", "CANCEL_FEE = 20000", $config_file);
    	preg_match("/CANCEL_FEE = [0-9]*/", $result, $match );
	}
	
	public function get($key){
		$value = "";
		preg_match("/$key = .*/", $this->config_file_content, $value);
		$value = $value ? $value[0] : "";
		$value = $value != "" ? substr($value, strlen($key) + 3) : $value;
		
		return $value;
	}
	
	public function set($key, $value){
		$this->config_file_content = preg_replace("/$key = .*/", "$key = $value", $this->config_file_content);
	}
	
	public function update(){
		file_put_contents($this->config_file_path, $this->config_file_content);
	}
}